#ifndef CELL_H
#define CELL_H

#include <QTableWidgetItem>

class Cell : public QTableWidgetItem
{
public:
    explicit Cell();
    explicit Cell(Cell* cell);

    /**
      @brief return a clone object.
      @return a cell instance which have the same value with orient.
    */
    virtual QTableWidgetItem* clone() const;

    /**
      descr:set the cell's data in according with role.
      param:role the input data's role; value cell's data.
    */
    virtual void setData(int role, const QVariant& value);

    /**
      descr:return cell's data in according with role.
      param:role the role about data.
      return:
    */
    virtual QVariant data(int role) const;

    void setFormula(const QString& formula);

    QString formula() const;

    /**
      descr:set the attribute of mCachedIsDirty to true for the cell
        content modified.
    */
    void setDirty();

private:
    QVariant value() const;
    QVariant evalExpression(const QString &str, int &pos) const;
    QVariant evalTerm(const QString &str, int &pos) const;
    QVariant evalFactor(const QString &str, int &pos) const;

private:
    //cell's content.
    mutable QVariant mCachedValue;

    //cell is modifed or not.
    mutable bool mCachedIsDirty;
};

#endif // CELL_H
